package org.luxor.common.netty.protocol.message;


import org.luxor.common.netty.protocol.NettyConnectVariableHeader;
import org.luxor.common.netty.protocol.NettyFixedHeader;
import org.luxor.common.netty.protocol.NettyMessageType;
import org.luxor.common.netty.protocol.NettyQoS;

/**
 * Netty Connect Message
 *
 * @author Mr.yan @date 2024/1/31
 */
public class NettyConnectMessage extends NettyMessage {

    public NettyConnectMessage(NettyFixedHeader fixedHeader, Object variableHeader) {
        super(fixedHeader, variableHeader, null);
    }

    @Override
    public NettyConnectVariableHeader variableHeader() {
        return (NettyConnectVariableHeader) super.variableHeader();
    }

    public static NettyConnectMessage from(String clientId) {
        return from(clientId, null, null);
    }

    public static NettyConnectMessage from(String clientId, String username, String password) {
        NettyFixedHeader fixedHeader = new NettyFixedHeader(NettyMessageType.CONNECT, false, NettyQoS.AT_MOST_ONCE);
        NettyConnectVariableHeader variableHeader = NettyConnectVariableHeader.from(clientId, username, password);
        return new NettyConnectMessage(fixedHeader, variableHeader);
    }

}
